﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MobileMake
{
     public static class ModelStateExtensions
    {
        public static IList<ErrorReasonInfo> GetAllErrors(this ModelStateDictionary modelState)
        {
            var errors = new List<ErrorReasonInfo>();

            foreach (var state in modelState)
            {
                if (state.Value.Errors.Count > 0)
                {
                    var err = new ErrorReasonInfo { PropertyName = state.Key };
                    foreach (var x in state.Value.Errors)
                    {
                        err.Error += x.ErrorMessage;
                    }
                    //state.Value.Errors(x => err.Error += x.ErrorMessage);

                    errors.Add(err);
                }
            }

            return errors;
        }
    }   
    
    public class OperationResultInfo
    {
        public OperationResultInfo()
        {
            Errors = new List<ErrorReasonInfo>();
        }

        public bool Successfull { get; set; }

        public string Message { get; set; }

        public IList<ErrorReasonInfo> Errors { get; set; }
    }

    public class ErrorReasonInfo
    {
        public string PropertyName { get; set; }

        public string Error { get; set; }
    }


}
